#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ERROR_CHECK(ret, num, msg) \
    {                              \
        if (ret == num)            \
        {                          \
            perror(msg);           \
            exit(1);               \
        }                          \
    }
int main(int argc, char *argv[])
{
    FILE *fp = fopen("testfile.txt", "r");
    ERROR_CHECK(NULL, fp, "fopen");
    int count = 0;
    //////////////////////////
    // char ch = 0;
    // while ((ch = fgetc(fp)) && (ch != EOF))
    // {
    //     if (ch == '\n')

    //         count++;
    // }

    /////////////////
    char buf[32] = {0};
    while (fgets(buf, sizeof(buf), fp))
    {
        if (buf[strlen(buf) - 1] == '\n')
        {
            count++;
        } 
    }
    printf("%d\n", count);
    return 0;
}
